import React, { Component } from 'react';
import { View, Image, Picker } from '@tarojs/components';
import { AtButton, AtCheckbox, AtForm, AtInput, AtFloatLayout, AtList, AtListItem, AtNavBar } from "taro-ui";
import Taro from '@tarojs/taro';
import "./myRoom.less";
import config from '../../config.json'

class myRoom extends Component<any, any>{
    constructor(...props) {
        super(props);
        this.state = {
            Opened: false,
            isSelect: false,
            array1: [],
            array2: [],
            datas1: [],
            datas2: [],
            checkedList1: [],
            checkedList2: [],
        }
    }


    componentDidMount() {
        this.load()
    }

    load() {
        let _this = this;
        Taro.request({
            url: config.domainName + "/user/admin/querymeetroom",
            method: "GET",
            data: {},
            header: {
                token: Taro.getStorageSync('token'),
            },
            success(res) {
                if (res.data.code === 0) {
                    _this.setState({
                        array1: res.data.data,
                    });
                    _this.setState({
                        datas1: res.data.data.map((item) => {
                            return {
                                value: item.umid,
                                label: item.name,
                                desc: item.note ? item.note : "没有描述"
                            }
                        })
                    })
                    console.log(_this.state.datas);
                    console.log("获取成功!");
                    console.log(_this.state);
                } else {
                    Taro.showToast({
                        title: '服务器异常',
                        icon: "error" as any
                    })
                }
            },
            fail() {
                console.log("获取失败!");
            }
        })
        Taro.request({
            url: config.domainName + '/meetroom/query',
            method: 'GET',
            data: {
                search: '',
                id: '',
            },
            header: {
                token: Taro.getStorageSync('token'),
            },
            success(res) {
                if (res.data.code === 0) {
                    _this.setState({
                        array2: res.data.data,
                    });
                    _this.setState({
                        datas2: _this.state.array2.map((item) => {
                            return {
                                value: item.mid,
                                label: item.name,
                                desc: item.note ? item.note : "没有描述"
                            }
                        })
                    })
                    console.log("获取成功!");
                    console.log(_this.state);
                } else {
                    Taro.showToast({
                        title: '服务器异常',
                        icon: "error" as any
                    })
                }

            },
            fail() {
                console.log("获取失败!");
            }
        })
    }
    render() {
        return (
            <>
                <AtNavBar
                    onClickLeftIcon={() => { Taro.navigateBack() }}
                    color='#000'
                    title='我的会议室'
                    leftIconType="chevron-left"
                />
                <View style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginRight: "20px" }}>
                    <View className="module-title">我的会议室</View>
                </View>

                <AtList>
                    {
                        this.state.array1.map((item) => {
                            return (
                                <AtListItem
                                    title={item.name}
                                    note={"面积：" + item.area + " | " + "投影仪：" + (() => { if (item.projector) { return "可用" } else { return "不可用" } })() + " | " + "网络：" + (() => { if (item.wifi) { return "可用" } else { return "不可用" } })()}
                                />
                            )
                        })
                    }
                </AtList>
            </>
        )
    }

}


export default myRoom;